"use strict";

/**
 * 测试api
 */

var Router = require('koa-router');
var config = require('../../config/index.js');
var appUtil = require('../../common/app_utils.js');
var errCodes = require('../../common/err_code.js');

var __pathPrefix = config.testApiPre + '/face/token';
console.log('router:' + __pathPrefix);
var router = new Router({prefix: __pathPrefix});

/**
 * 申请token,这个api会关闭,会由 以前的 api服务器提供
 * get /api/v1/face/token?uid=123
 */
router.get('/', function*() {
  var uid = this.request.inParams.fields.uid;
  if (!uid) {
    return appUtil.ferror(errCodes.E_ARGS_INVALID, 'uid');
  }

  var token = appUtil.genToken(uid);
  var result = {token: token};
  this.body = appUtil.fout(result);
});

module.exports = router.routes();